﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Core;
using Core.LockStep;
using UnityEngine.InputSystem;

public class GameInputSystem : EntitySystem, IInterpolationUpdateSystem, IStepDataSender
{
    public StepData1MoveData moveDate = new StepData1MoveData();
    private bool isHaveInput;

    public void SendStepData()
    {
        if (!isHaveInput)
            return;
        isHaveInput = false;

        moveDate.PlayerId = BattleDataTool.helper.PlayerId;

        new SendStepData(moveDate).Publish();
    }

    public void InterpolationUpdate(float deltaTime)
    {
        var x = 0;
        var z = 0;

        if (Keyboard.current.leftArrowKey.isPressed)
            x = -1;
        else if (Keyboard.current.rightArrowKey.isPressed)
            x = 1;

        if (Keyboard.current.upArrowKey.isPressed)
            z = 1;
        else if (Keyboard.current.downArrowKey.isPressed)
            z = -1;

        if (x != 0 || z != 0)
            isHaveInput = true;

        moveDate.inputDelta.x = x;
        moveDate.inputDelta.z = z;
    }

}